﻿using helloworld2.MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace helloworld2.CTR
{
    class CtrSOTR
    {
        public double batteryLeftKM { get; set; }
        private List<SOTR> road;
        private double distance = 200;
        
        public CtrSOTR(List<Object> roadToCheck, double batteryLeftProcent)
        {
            findBatteryLeft(batteryLeftProcent);
            makeStops(roadToCheck);


        }

        private void findBatteryLeft(double batteryLeftProcent)
        {
            double calculate = distance*(batteryLeftProcent/100);
            batteryLeftKM = calculate;
        }

        private void makeStops(List<Object> roadToCheck)
        {
            SOTR lastStation = null;
            double lengthToNext = 0;

            foreach(Object o in roadToCheck)
            {
                SOTR sotr = new SOTR();

                if (o is City)
                {
                    lastStation.lengthToNext = lengthToNext;
                    City c = o as City;
                    sotr.setCoordinats(c.getCoordinates());
                    sotr.lastStation = lastStation;
                    
                    lastStation = sotr;
                    lengthToNext = 0;
                    
                }
                if (o is Station)
                {
                    lastStation.lengthToNext = lengthToNext;
                    Station s = o as Station;
                   // sotr.setCoordinats(s.);
                    sotr.lastStation = lastStation;
                    lastStation = sotr;
                    lengthToNext = 0;
                }
                if (o is Road)
                {
                    Road r = o as Road;
                    lengthToNext = lengthToNext + r.length;
                }
            }
        }

    }
}
